package homewoek12月19号.homwwork.h5;

import org.apache.commons.beanutils.BeanUtils;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;

public class Demo1 {
    public static void main(String[] args) throws DocumentException, ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException {
        Element root = new SAXReader().read("src/com/czxy/homwwork/h5/student.xml").getRootElement();
        List<Element> slist = root.elements("student");
        for (Element e : slist) {
            HashMap<String, Object> map = new HashMap<>();
            List<Element> elist = e.elements();
            for (Element element : elist) {
                map.put(element.getName(),e.elementText(element.getName()));
            }
            student student = new student();
            BeanUtils.populate(student,map);
            System.out.println(student);
        }
    }
}
